﻿using System;
using System.Collections.Generic;
using System.Text;
//第30行代码用于测试功能，测试功能请注释掉29行并启用30行代码
namespace creditcard
{
    public class program
    {
        private static int flag;
        private static long costmoney;

        public static int Succeed_Or_Defeat
        {
            get { return flag; }
            set { flag = value; }
        }
        public static long cost
        {
            get { return costmoney; }
            set { costmoney += value; }
        }
        class Delegratemoney
        {
            public delegate void Payback();
            public event Payback Pay;
            public void Test()
            {

                if(Pay != null&& DateTime.Now.ToShortDateString().ToString()[^0]=='1'&& DateTime.Now.ToShortDateString().ToString()[^1]=='-')
                //if (Pay != null)  本行代码用于测试功能，
                {
                    Pay();
                    if (Succeed_Or_Defeat == 1)
                    {
                        Console.WriteLine("还款成功！");
                        Succeed_Or_Defeat = 0;
                    }
                    else Console.WriteLine("还款失败！");
                }
                else Console.WriteLine("还款失败！");
            }
        }
        class Debit
        {
            private long m;
            public long money
            {
                get { return m; }
                set 
                {
                    if (value > 0) m += value;
                    else Console.WriteLine("error!");
                }
            }
            public void Payback()
            {
                if (money >= cost&& Succeed_Or_Defeat==0)
                {
                    money -= cost;
                    Succeed_Or_Defeat = 1;
                    cost = 0;
                }
            }
        }
        static void Main(string[] arg)
        {
            Delegratemoney @delegratemoney = new Delegratemoney();
            

            Debit debit1 = new Debit();
            Debit debit2 = new Debit();
            Debit debit3 = new Debit();
            debit1.money = 1000;
            debit2.money = 500;
            debit3.money = 100;
            cost = 2000;
            @delegratemoney.Pay += new Delegratemoney.Payback(debit1.Payback);
            @delegratemoney.Pay += new Delegratemoney.Payback(debit2.Payback);
            @delegratemoney.Pay += new Delegratemoney.Payback(debit3.Payback);

            @delegratemoney.Test();

            debit2.money = 2000;
            @delegratemoney.Test();




        }
    }
}